package cn.sxw.ld.module.scrolling.service.impl;

import cn.sxw.ld.common.utils.CommonUtil;
import cn.sxw.ld.module.scrolling.mapper.ScrollingMapper;
import cn.sxw.ld.module.scrolling.pojo.Scrolling;
import cn.sxw.ld.module.scrolling.service.ScrollingService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:ScrollingServiceImpl
 * Package:cn.sjxy.graduation.service.impl
 * Description:
 *
 * @Date:2022/6/24 16:39
 * @Author:SXW
 */
@Service
@Slf4j
public class ScrollingServiceImpl extends ServiceImpl<ScrollingMapper, Scrolling> implements ScrollingService {


    @Override
    public Page getPage(int page, int pageSize, int type) {
        // 分页查询
        Page<Scrolling> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<Scrolling> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Scrolling::getType, type);
        this.page(pageInfo, wrapper);
        return pageInfo;
    }

    @Override
    public List<Scrolling> getlist(int type) {
        LambdaQueryWrapper<Scrolling> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Scrolling::getType, type);
        return this.list(wrapper);
    }

    /**
     * 获取滚动字幕的段落
     *
     * @param id
     * @return
     */
    @Override
    public List<Scrolling> getParagraph(Long id) {
        Scrolling scrolling = this.getById(id);
        if (scrolling != null) {
            if (scrolling.getType() != 1) {
                return null;
            }
            String content = scrolling.getContent();
            return CommonUtil.splitSentences(content);
        } else {
            return null;
        }
    }
}
